<template>
  <div>
    <el-menu
      style="width: 200px; min-height: calc(100vh - 50px)"
      :default-active="path"
      router
      class="el-menu-vertical-demo"
    >
      <el-sub-menu index="1" v-if="user?.role === 1">
        <template #title
          ><el-icon><Document /></el-icon>系统管理</template
        >
        <el-menu-item index="/user"
          ><el-icon><Location /></el-icon>用户管理</el-menu-item
        >
      </el-sub-menu>
      <el-sub-menu index="2">
        <template #title
          ><el-icon><Document /></el-icon>数据管理</template
        >
        <el-menu-item index="/coupons"
          ><el-icon><Menu /></el-icon>优惠券管理</el-menu-item
        >
        <el-menu-item index="/commoditys"
          ><el-icon><Menu /></el-icon>商品管理</el-menu-item
        >
      </el-sub-menu>
    </el-menu>
  </div>
</template>

<script lang="ts" setup>
// @ts-nocheck
// import {Location, Setting, Menu, Document} from '@element-plus/icons'
import request from '@/utils/request'
import { useRoute } from 'vue-router'
import { ref } from 'vue'

const userStr = sessionStorage.getItem('user') || '{}'
const user: any = ref(JSON.parse(userStr))
const route = useRoute()
const path = ref(route.path)

// 请求服务器，确认当前登录用户的合法信息
request.get('/user/' + user.value.id).then((res) => {
  if (res.code === '200') {
    user.value = res.data
  }
})
</script>

<style scoped></style>
